<?php
 
defined("_VALID_ACCESS") || die('Direct access forbidden'); // - security feature
 
class SCTV_MaintenanceDeployment extends Module { // - notice how the class name represents its path
	public function today()
	{
		$tb = $this->init_module('Utils/TabbedBrowser');		
		$tb->set_tab(__('Delivery Maintenance'). ' ' . __('Today') . ' ' . date('d-m-Y'), array($this, 'deployment_today'));				
		$tb->set_tab(__('Detail delivery Maintenance'). ' ' . __('Today') . ' ' . date('d-m-Y'), array($this, 'report_today'));
        $tb->set_tab(__('Maintenance Transition'), array($this, 'transition_today'));
		$this->display_module($tb);	
		$tb->tag();
	}
	public function tomorrow()
	{
		$tb = $this->init_module('Utils/TabbedBrowser');		
		$tb->set_tab(__('Delivery Maintenance'). ' ' . __('Tomorrow') . ' ' . date('d-m-Y', strtotime('+1 day')), array($this, 'deployment_tomorrow'));				
		$tb->set_tab(__('Detail delivery Maintenance'). ' ' . __('Tomorrow') . ' ' . date('d-m-Y', strtotime('+1 day')), array($this, 'report_tomorrow'));
		$this->display_module($tb);	
		$tb->tag();
	}
	public function deployment_today()
	{
		$date = date('Y-m-d');
				
  		if (isset($_REQUEST['submited']))
		{
			$submited = $_REQUEST['submited'];
			
			if($submited == 0)
			{
				$this->set_module_variable('area', $_REQUEST['area']);
				//$uncompleted = isset($_REQUEST['uncompleted'])?$_REQUEST['uncompleted']:0;					
				//$this->set_module_variable('uncompleted', $uncompleted);
			}				
			
			if($submited == 1)
			{
				$_values = array_filter(explode(HTML_QuickForm_automulti::$list_sep, $_REQUEST['maintenance']));
				
				$employee = $_REQUEST['employee'];
				if($employee != null)
				{
                    $send_sms = $_REQUEST['send_sms'];
					foreach ($_values as $key => $value) {
						if(SCTV_MaintenanceDeploymentCommon::deployment_not_exists($value, $date, $employee)){
                            $deployment = Utils_RecordBrowserCommon::new_record('SCTV_MaintenanceDeployment',array('maintenance'=>$value, 'date'=>$date, 'technical'=>$employee));
                            if($send_sms == 1){
                                self::send_sms($deployment, false);
                            }
                        }
					}	
				}
				else {
					$manager_area = $_REQUEST['manager_area'];
					if($manager_area != null)
					{
						foreach ($_values as $key => $value) {
							$deployment = Utils_RecordBrowserCommon::update_record('SCTV_Maintenance', $value, array('manager_area'=>$manager_area));
						}	
					}
				}						
			}
			else
			{																
			}					
		}
					
		$form = & $this->init_module('Libs/QuickForm');
		$form->reset();
		
		// Lay thoi gian he thong
		// Neu thoi gian thuc hien sau 8h toi, thi giao phieu cho ngay hom sau
		// Con lai giao phieu trong ngay
		
		$datetime = new DateTime($date);
		$form->addElement('Header', 'header', __('Assigning to date'). ' ' . $datetime->format('d/m/Y'));
								
		$manager =  CRM_ContactsCommon::get_my_record();
		$i_am_admin = Base_AclCommon::i_am_admin();
		
		$options = SCTV_AreaCommon::get_area($i_am_admin, $manager['id']);
		$form->addElement('select','area',__('Area'), $options, array('onchange'=>$form->get_submit_form_js(false)));
		//$form->addElement('checkbox','uncompleted',__('Display the today\' assigned maintenance but uncompleted'), null, array('onchange'=>$form->get_submit_form_js(false)));
		$area = $this->get_module_variable('area');
		//$uncompleted = $this->get_module_variable('uncompleted');
		
		$form->setDefaults(array('area'=>$area));//, 'uncompleted'=>$uncompleted));		
		$form->display_as_column();

		$form_assigment = & $this->init_module('Libs/QuickForm');
		//$form_assigment->reset();		
		
		$maintenance = SCTV_MaintenanceCommon::get_maintenance_by_area($date, $area, $i_am_admin, $manager['id']);			
		$multi = $form_assigment->addElement('multiselect', 'maintenance', __('Maintenance') . '(' . count($maintenance) . ')', $maintenance, 
			array(
				'id'=>'maintenance',
                'style'=>'height:256px'
			)
		);
		eval_js("ms_remove_all('maintenance', '__SEP__')");
		$js = "jQuery('#submit_button').prop('value', '" . __('Assign') . "(" . __('Number of maintenance') . ": ' + document.getElementsByName('maintenanceto[]')[0].options.length +')')";
		$multi->on_add_js($js);
		$multi->on_remove_js($js);
		
		if($i_am_admin)
		{
			$form_assigment->addElement('select','manager_area',__('Manager Area'), $options);
		}	
		else
		{	
			if($area == 13)		
				$form_assigment->addElement('autoselect', 'employee', __('Employee'), array(), array(array('CRM_ContactsCommon','autoselect_contact_suggestbox'), array(array('group'=>'Technical'), array('CRM_ContactsCommon', 'contact_format_default'))), array('CRM_ContactsCommon', 'contact_format_default'), array('id'=>'employee'));
			else
				$form_assigment->addElement('autoselect', 'employee', __('Employee'), array(), array(array('CRM_ContactsCommon','autoselect_contact_suggestbox'), array(array('group'=>'Technical', 'manager'=>$manager['id']), array('CRM_ContactsCommon', 'contact_format_default'))), array('CRM_ContactsCommon', 'contact_format_default'), array('id'=>'employee'));

            $form_assigment->addElement('checkbox','send_sms','Gửi tin nhắn SMS');
		}
		
		$submit = $form_assigment->createElement('submit','submit_button',__('Assign'), array('id'=>'submit_button'));
		$form_assigment->addGroup(array($submit));
				
			
		$form_assigment->display();
										
		$gb_area = $this->init_module('Utils/GenericBrowser',null,'area_statictis');
		$gb_area->set_table_columns(array(
			array('name'=>__('Area')),
			array('name'=>__('Planned'), 'width'=>40),
			array('name'=>__('Assigned'), 'width'=>40),
			array('name'=>__('Remaining'), 'width'=>40)
		));
					
				
		$recs = SCTV_MaintenanceCommon::get_maintenance_statictis_area($date, $i_am_admin, $manager['id']);
		
		$sum_planned = 0;
		$sum_assigned = 0;
		
		foreach ($recs as $key => $value) 
		{
			$planned = $value['planned'];
			$sum_planned += $planned;
			 
			$assigned = $value['assigned'];
			$sum_assigned += $assigned; 
			
			$remaining = $planned - $assigned; 
			  
			$gb_area->add_row(
				$value['f_name'],
				$planned,
				$assigned,
				$remaining>=0?$remaining:0);			
		}

		$remaining = $sum_planned - $sum_assigned;
		$gb_area->add_row(
				'<strong>' . __('Total') . '</strong>',
				'<strong>' . $sum_planned . '</strong>',
				'<strong>' . $sum_assigned . '</strong>',
				'<strong>' . ($remaining>=0?$remaining:0) . '</strong>');
			
			
		$this->display_module($gb_area);
			                   
		$gb_employee = $this->init_module('Utils/GenericBrowser',null,'employee_statictis');
		$gb_employee->set_table_columns(array(
			array('name'=>__('Employee')),
			array('name'=>__('Assigned'), 'width'=>40),
			array('name'=>__('Completed'), 'width'=>40),
			array('name'=>__('Remaining'), 'width'=>40)
		));
		
		$keymd5 = md5(time());
        $_SESSION[$key] = array(
         	'date'=>$date,
        );        
			
		$recs = SCTV_MaintenanceCommon::get_maintenance_statictis_technical($date, $i_am_admin, $manager['id']);
		foreach ($recs as $key => $value) 
		{
			$print_href = 'href="modules/SCTV/MaintenanceDeployment/print.php?'.http_build_query(array('key'=>$keymd5, 'cid'=>CID, 'employee'=>$value['id'], 'date'=>$date)).'" target="_blank"';
			
			$remaining = $value['assigned']-$value['completed'];
			
			$gb_row = $gb_employee->get_new_row();			
			$gb_row->add_data(
				'<a '.$print_href.'>'.$value['fullname'] .'</a>',
				$value['assigned'],
				$value['completed'],
				$remaining>=0?$remaining:0
				);
			$gb_row->add_action($print_href,'View');			
		}
			
		$this->display_module($gb_employee);   
	}
	public function deployment_tomorrow()
	{
		$date = date('Y-m-d', strtotime('+1 day'));		
							
  		if (isset($_REQUEST['submited']))
		{
			$submited = $_REQUEST['submited'];
			
			if($submited == 0)
			{
				$this->set_module_variable('area', $_REQUEST['area']);
			}				
			
			if($submited == 1)
			{
				$_values = array_filter(explode(HTML_QuickForm_automulti::$list_sep, $_REQUEST['requirements']));
				
				$employee = $_REQUEST['employee'];
				if($employee != null)
				{
					foreach ($_values as $key => $value) {
						if(SCTV_MaintenanceDeploymentCommon::deployment_not_exists($value, $date, $employee))
							$deployment = Utils_RecordBrowserCommon::new_record('SCTV_MaintenanceDeployment',array('maintenance'=>$value, 'date'=>$date, 'technical'=>$employee));
					}	
				}						
			}
			else
			{																
			}					
		}
					
		$form = & $this->init_module('Libs/QuickForm');
		$form->reset();
		
		
		// Lay thoi gian he thong
		// Neu thoi gian thuc hien sau 8h toi, thi giao phieu cho ngay hom sau
		// Con lai giao phieu trong ngay
		
		$datetime = new DateTime($date);
		$form->addElement('Header', 'header', __('Assigning to date'). ' ' . $datetime->format('d/m/Y'));
								
		$manager =  CRM_ContactsCommon::get_my_record();
		$i_am_admin = Base_AclCommon::i_am_admin();
		
		$options = SCTV_AreaCommon::get_area($i_am_admin, $manager['id']);
		$form->addElement('select','area',__('Area'), $options, array('onchange'=>$form->get_submit_form_js(false)));
		$area = $this->get_module_variable('area');
		
		$form->setDefaults(array('area'=>$area));		
		$form->display_as_column();

		$form_assigment = & $this->init_module('Libs/QuickForm');
		//$form_assigment->reset();		
		
		$maintenance = SCTV_MaintenanceCommon::get_maintenance_by_area($date, $area, $i_am_admin, $manager['id']);			
		$multi = $form_assigment->addElement('multiselect', 'maintenance', __('Maintenance') . '(' . count($maintenance) . ')', $maintenance,
            array(
                'id'=>'maintenance',
                'style'=>'height:256px'
            )
        );
		eval_js("ms_remove_all('maintenance', '__SEP__')");
		
		$js = "jQuery('#submit_button').prop('value', '" . __('Assign') . "(" . __('Number of requiremens') . ": ' + document.getElementsByName('maintenanceto[]')[0].options.length +')')";
		$multi->on_add_js($js);
		$multi->on_remove_js($js);
						
		if($area == 13)		
			$form_assigment->addElement('autoselect', 'employee', __('Employee'), array(), array(array('CRM_ContactsCommon','autoselect_contact_suggestbox'), array(array('group'=>'Technical'), array('CRM_ContactsCommon', 'contact_format_default'))), array('CRM_ContactsCommon', 'contact_format_default'), array('id'=>'employee'));
		else
			$form_assigment->addElement('autoselect', 'employee', __('Employee'), array(), array(array('CRM_ContactsCommon','autoselect_contact_suggestbox'), array(array('group'=>'Technical', 'manager'=>$manager['id']), array('CRM_ContactsCommon', 'contact_format_default'))), array('CRM_ContactsCommon', 'contact_format_default'), array('id'=>'employee'));
		
		$submit = $form_assigment->createElement('submit','submit_button',__('Assign'), array('id'=>'submit_button'));
		$form_assigment->addGroup(array($submit));
			
		$form_assigment->display();
										
		$gb_area = $this->init_module('Utils/GenericBrowser',null,'area_statictis');
		$gb_area->set_table_columns(array(
			array('name'=>__('Area')),
			array('name'=>__('Waiting'), 'width'=>40),
			array('name'=>__('Assigned'), 'width'=>40),
			array('name'=>__('Remaining'), 'width'=>40)
		));
					
		$recs = SCTV_MaintenanceCommon::get_maintenance_statictis_area($date, $i_am_admin, $manager['id']);
		
		$sum_planned = 0;
		$sum_assigned = 0;
		
		foreach ($recs as $key => $value) 
		{
			$planned = $value['planned'];
			$sum_planned += $planned;
			 
			$assigned = $value['assigned'];
			$sum_assigned += $assigned; 
			  
			$gb_area->add_row(
				$value['f_name'],
				$planned,
				$assigned,
				$planned - $assigned);			
		}

		$gb_area->add_row(
				'<strong>' . __('Total') . '</strong>',
				'<strong>' . $sum_planned . '</strong>',
				'<strong>' . $sum_assigned . '</strong>',
				'<strong>' . ($sum_planned - $sum_assigned) . '</strong>');
			
			
		$this->display_module($gb_area);
			                   
		$gb_employee = $this->init_module('Utils/GenericBrowser',null,'employee_statictis');
		$gb_employee->set_table_columns(array(
			array('name'=>__('Employee')),
			array('name'=>__('Assigned'), 'width'=>40),
			array('name'=>__('Completed'), 'width'=>40),
			array('name'=>__('Remaining'), 'width'=>40)
		));
		
		$keymd5 = md5(time());
        $_SESSION[$key] = array(
         	'date'=>$date,
        );        
			
		$recs = SCTV_MaintenanceCommon::get_maintenance_statictis_technical($date, $i_am_admin, $manager['id']);
		foreach ($recs as $key => $value) 
		{
			$print_href = 'href="modules/SCTV/MaintenanceDeployment/print.php?'.http_build_query(array('key'=>$keymd5, 'cid'=>CID, 'employee'=>$value['id'], 'date'=>$date)).'" target="_blank"';
			$gb_row = $gb_employee->get_new_row();
			$gb_row->add_data(
				'<a '.$print_href.'>'.$value['fullname'] .'</a>',
				$value['assigned'],
				$value['completed'],
				$value['assigned']-$value['completed']
				);
			$gb_row->add_action($print_href,'View');
		}
			
		$this->display_module($gb_employee);   
	}
    public function transition_today()
    {
        $date = date('Y-m-d');

        if (isset($_REQUEST['submited']))
        {
            $submited = $_REQUEST['submited'];

            if($submited == 0)
            {
                $this->set_module_variable('area', $_REQUEST['area']);
            }

            if($submited == 1)
            {
                $_values = array_filter(explode(HTML_QuickForm_automulti::$list_sep, $_REQUEST['maintenance']));

                $manager_area = $_REQUEST['manager_area'];
                if($manager_area != null)
                {
                    foreach ($_values as $key => $value) {
                        $deployment = Utils_RecordBrowserCommon::update_record('SCTV_Maintenance', $value, array('manager_area'=>$manager_area));
                    }
                }
            }
            else
            {
            }
        }

        $form = & $this->init_module('Libs/QuickForm');
        $form->reset();

        // Lay thoi gian he thong
        // Neu thoi gian thuc hien sau 8h toi, thi giao phieu cho ngay hom sau
        // Con lai giao phieu trong ngay

        $datetime = new DateTime($date);
        $form->addElement('Header', 'header', __('Maintenance Transition'));

        $manager =  CRM_ContactsCommon::get_my_record();
        $i_am_admin = Base_AclCommon::i_am_admin();

        $options = SCTV_AreaCommon::get_area($i_am_admin, $manager['id']);
        $form->addElement('select','area',__('Area'), $options, array('onchange'=>$form->get_submit_form_js(false)));
        //$form->addElement('checkbox','uncompleted',__('Display the today\' assigned maintenance but uncompleted'), null, array('onchange'=>$form->get_submit_form_js(false)));
        $area = $this->get_module_variable('area');
        //$uncompleted = $this->get_module_variable('uncompleted');

        $form->setDefaults(array('area'=>$area));//, 'uncompleted'=>$uncompleted));
        $form->display_as_column();

        $form_assigment = & $this->init_module('Libs/QuickForm');
        //$form_assigment->reset();

        $maintenance = SCTV_MaintenanceCommon::get_maintenance_by_area($date, $area, $i_am_admin, $manager['id']);
        $multi = $form_assigment->addElement('multiselect', 'maintenance', __('Maintenance') . '(' . count($maintenance) . ')', $maintenance,
            array(
                'id'=>'maintenance'
            )
        );
        eval_js("ms_remove_all('maintenance', '__SEP__')");
        $js = "jQuery('#submit_button').prop('value', '" . __('Assign') . "(" . __('Number of requiremens') . ": ' + document.getElementsByName('maintenanceto[]')[0].options.length +')')";
        $multi->on_add_js($js);
        $multi->on_remove_js($js);

        $options = SCTV_AreaCommon::get_area_is_not_manager($i_am_admin, $manager['id']);
        $form_assigment->addElement('select','manager_area',_M('Destination Area'), $options);

        $submit = $form_assigment->createElement('submit','submit_button',__('Assign'), array('id'=>'submit_button'));
        $form_assigment->addGroup(array($submit));

        $form_assigment->display();

        $gb_area = $this->init_module('Utils/GenericBrowser',null,'area_statictis');
        $gb_area->set_table_columns(array(
            array('name'=>__('Area')),
            array('name'=>__('Planned'), 'width'=>40),
            array('name'=>__('Assigned'), 'width'=>40),
            array('name'=>__('Remaining'), 'width'=>40)
        ));


        $recs = SCTV_MaintenanceCommon::get_maintenance_statictis_area($date, $i_am_admin, $manager['id']);

        $sum_planned = 0;
        $sum_assigned = 0;

        foreach ($recs as $key => $value)
        {
            $planned = $value['planned'];
            $sum_planned += $planned;

            $assigned = $value['assigned'];
            $sum_assigned += $assigned;

            $remaining = $planned - $assigned;

            $gb_area->add_row(
                $value['f_name'],
                $planned,
                $assigned,
                $remaining>=0?$remaining:0);
        }

        $remaining = $sum_planned - $sum_assigned;
        $gb_area->add_row(
            '<strong>' . __('Total') . '</strong>',
            '<strong>' . $sum_planned . '</strong>',
            '<strong>' . $sum_assigned . '</strong>',
            '<strong>' . ($remaining>=0?$remaining:0) . '</strong>');


        $this->display_module($gb_area);
    }
	public function report()
	{
		$tb = $this->init_module('Utils/TabbedBrowser');		
		$tb->set_tab(__('Today' . ' ' . date('d-m-Y')), array($this, 'report_today'));				
		$tb->set_tab(__('Tomorrow' . ' ' . date('d-m-Y', strtotime('+1 day'))), array($this, 'report_tomorrow'));
		$this->display_module($tb);	
		$tb->tag();
	}
	public function report_today()
	{
		$form = $this->report_form();
		
		if(isset($_REQUEST['submited']))
		{
			if(isset($_REQUEST['employee'])) $this->set_module_variable('employee', $_REQUEST['employee']);					
		}
						
		//if($this->isset_module_variable('employee'))
		{
			$date = date('Y-m-d');
			$manager =  CRM_ContactsCommon::get_my_record();
			$i_am_admin = Base_AclCommon::i_am_admin();
			$recs = SCTV_MaintenanceCommon::get_maintenance_by_technical( strtotime($date), $this->get_module_variable('employee', null), $manager['id'], $i_am_admin);
			$this->report_show_result($date, $recs, 'deployment_employee');
		}
	}
	public function report_tomorrow()
	{
		$form = $this->report_form();
		
		if(isset($_REQUEST['submited']))
		{
			if(isset($_REQUEST['employee'])) $this->set_module_variable('employee', $_REQUEST['employee']);					
		}
						
		//if($this->isset_module_variable('employee'))
		{
			$date = date('Y-m-d', strtotime('+1 day')); 		
			$manager =  CRM_ContactsCommon::get_my_record();
			$i_am_admin = Base_AclCommon::i_am_admin();
			$recs = SCTV_MaintenanceCommon::get_maintenance_by_technical($date, $this->get_module_variable('employee', null), $manager['id'], $i_am_admin);
			$this->report_show_result($date, $recs, 'deployment_employee');
		}
	}
	private function report_form()
	{
		$form = $this->init_module('Libs/QuickForm',null,__('Assignment') . ': ' . __('Report'));
		
		$manager =  CRM_ContactsCommon::get_my_record();
		$form->addElement('autoselect', 'employee', __('Deployment Employee'), array(), array(array('CRM_ContactsCommon','autoselect_contact_suggestbox'), array(array('group'=>'Technical', 'manager'=>$manager['id']), array('CRM_ContactsCommon', 'contact_format_default'))), array('CRM_ContactsCommon', 'contact_format_default'), array('style'=>'width:300px', 'onchange'=>$form->get_submit_form_js(true)));
		//$form->addElement('checkbox', 'only_incomplete', __('Show only incomplete'), array(), array('onchange'=>$form->get_submit_form_js(true)));
		
		if ($form->validate()) {
			$filters = $form->exportValues();								
		}
		else {
			$filters = array('employee'=>null);
		}
		
		$form->setDefaults($filters);		
		$form->display_as_row();
		
		return $form;
	}
    public  function send_sms($deployment_id, $show_message){
        $danang_id = SCTV_MaintenanceCommon::get_danang_id();
        $maintenances = DB::Execute("select * from sctv_maintenance_assigned_one(%d, %d)", array($danang_id, $deployment_id));

        foreach($maintenances as $key=>$maintenance)
        {
            $content ='#' . $maintenance['maintenance_code'] . ' ' . $maintenance['customer_name'] . '(' . $maintenance['address'] . ' ' . $maintenance['street'] . '[' . $maintenance['area'] . ']'. ', ĐT: ' . $maintenance['phone'] . ')';
            if($maintenance['note'] != null)
                $content .='. Ghi chú: ' . $maintenance['note'];
            if($maintenance['charge'] > 0)
                $content .='. Chốt cước nóng: ' . number_format($maintenance['charge'], 0, ',', '.');

            $dbconn=pg_connect("host=localhost port=5432 dbname=sms user=postgres password=admin");

            $contact = Utils_RecordBrowserCommon::get_record('contact', $maintenance['technical_id'], array('mobile_phone_sms', 'mobile_phone_sms_1'));
            if(!empty($contact[mobile_phone_sms])){
                SCTV_MaintenanceSmsCommon::send_out($dbconn, $contact[mobile_phone_sms], $content, 'ASSIGN', $maintenance['maintenance_id'], $maintenance['technical_id']);
            }

            if(!empty($contact[mobile_phone_sms_1])){
                SCTV_MaintenanceSmsCommon::send_out($dbconn, $contact[mobile_phone_sms_1], $content, 'ASSIGN', $maintenance['maintenance_id'], $maintenance['technical_id']);
            }

            if($show_message)
                eval_js('alert("' . $content . '")');

            break;
        }
    }
	public function unassignment($deployment_id)
	{
		Utils_RecordBrowserCommon::delete_record('SCTV_MaintenanceDeployment',$deployment_id); 
	}
	private function report_show_result($date, $recs)
	{
		Base_ActionBarCommon::add('save', __('Export'), 'href="modules/SCTV/MaintenanceDeployment/export.php?'.http_build_query(array('cid'=>CID, 'date'=>$date)).'"');
		$current_technical_id = null;
							
		foreach ($recs as $key => $value){
			$technical_id = $value['technical_id'];
			if($current_technical_id === null || $current_technical_id != $technical_id){
				if($current_technical_id != null)
				{
					$this->display_module($gb);
				}
				
				$current_technical_id = $technical_id; 
				$gb = $this->init_module('Utils/GenericBrowser', null, $value['technical_name']);
				$gb->set_table_columns(array(
					array('name'=>__('Requirement Code'), 'width'=>'70px'),
					array('name'=>__('Customer Name'), 'width'=>'120px'),
					array('name'=>__('Address'), 'width'=>'70px'),
					array('name'=>__('Street'), 'width'=>'100px'),
					array('name'=>__('Area'), 'width'=>'90px'),
					array('name'=>__('Ward'), 'width'=>'70px'),
					array('name'=>__('District'), 'width'=>'60px'),				
					array('name'=>__('Phone'), 'width'=>'80px'),
					array('name'=>__('Note'), 'width'=>'100px'),
					array('name'=>__('Charge'), 'width'=>'70px'),					
				));
				$keymd5 = md5(time());
        		$_SESSION[$keymd5] = array(
         			'date'=>$date,
		        ); 
				
				$print_href = 'href="modules/SCTV/MaintenanceDeployment/print.php?'.http_build_query(array('key'=>$keymd5, 'cid'=>CID, 'employee'=>$current_technical_id, 'date'=>$date)).'" target="_blank"';
				$gb->set_prefix('<a '.$print_href.'>'.$value['technical_name'] .'</a>');
			}			
			
			$gb_row = $gb->get_new_row();
			$gb_row->add_data( 
					$value['requirement_code'],
					$value['customer_name'],
					$value['address'],
					$value['street'],
					$value['area'],
					$value['ward'],
					$value['district'],					
					$value['phone'],
					$value['note'],
					Utils_CurrencyFieldCommon::format($value['charge'])					
			);
			
			if($value['status'] == '0'){
                $gb_row->add_action($this->create_confirm_callback_href(__('Unassignment'). ' '. $value['technical_name'] . '/' . $value['customer_name'] .'?',array($this,'unassignment'), array($value['deployment_id'])),'Delete');
                $gb_row->add_action(
                    $this->create_callback_href(array($this, 'send_sms'), array($value['deployment_id'], true)),
                    'SMS', 'SMS', Base_ThemeCommon::get_template_file('Utils_GenericBrowser', 'active-on.png')
                );
            }
		}

		if($current_technical_id != null)
		{
			$this->display_module($gb);
		}
	}
	public function caption(){
		if (isset($this->rb)) return $this->rb->caption();
	}
	public function maintenance_deployment_addon($arg){
		$rb = $this->init_module('Utils/RecordBrowser','SCTV_MaintenanceDeployment');		
		$Deployment = array(array('maintenance'=>$arg['id']), array(), array());
		$this->display_module($rb,$Deployment,'show_data');
	}
}
 
?>